package Thread;

public class ThreadDemo9 {
     static Object object = new Object();
    public static void main(String[] args) {
        Thread t = new Thread(()->{
         synchronized (object){
             //  while (true){

             System.out.println("hello");

             try {
                 Thread.sleep(2000);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
             try {
                 object.wait();
                 System.out.println("777");
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
         }
            //   }
        });
        System.out.println(t.getState());//获取线程状态
        t.start();
        synchronized (object){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getState());

        }
        System.out.println("666");
        object.notify();

    }
    //NEW 线程创建了但没有运行
    //RUNNABLE 线程就绪状态:1.正在运行 2.随时可以运行
    //TERMINATED 线程结束但是线程对象还存在
    //TIME_WAITING 表示线程等待或阻塞状态
    //BLOCKED 等待锁状态
}
